package com.zykj.iterator.zuhe;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Title: Menu
 * @Project: ${MODEL_NAME}
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 10
 * @since 2019/1/7-21:10
 */
public class Menu extends MenuComponent {
    ArrayList menuComponents = new ArrayList();

    private String name;
    private String description;

    public Menu(String name, String description) {
        this.name = name;
        this.description = description;
    }

    public void add(MenuComponent menuComponent) {
        menuComponents.add(menuComponent);
    }
    public MenuComponent getChild(int i) {
        return (MenuComponent)menuComponents.get(i);
    }

    public String getName() {
        return name;
    }

    public String getDescription() {
        return description;
    }

    public void print() {
        System.out.println(name+", "+description);
        System.out.println("----------------------------------------");
        //TODO 这里是组合模式的重点
        //  这里就能打印子菜单的内容了
        Iterator iterator = menuComponents.iterator();
        while (iterator.hasNext()) {
            MenuComponent menuComponent = (MenuComponent) iterator.next();
            menuComponent.print();
        }
    }
}
